﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using WindowsGame.Data;
using WindowsGame.Enums;
using WindowsGame.Static;
using WindowsGame.Library.Data;
using WindowsGame.Library.IoC;
using WindowsGame.Tests.Data;
using NUnit.Framework;

namespace WindowsGame.Tests.Manager
{
	[TestFixture]
	public class FileManagerTests
	{
		// System under test.
		private IFileManager fileManager;

		[TestFixtureSetUp]
		public void TestFixtureSetUp()
		{
			IoCContainer.Initialize<IFileProxy, TestFileProxy>();
			IoCContainer.Initialize<IFileManager, FileManager>();
		}

		[SetUp]
		public void SetUp()
		{
			fileManager = IoCContainer.Resolve<IFileManager>();
		}

		[Test]
		public void OffsetsDataTest()
		{
			String offsetsFile = GetPath("Offsets.xml");

			OffsetData[] offsets = fileManager.LoadXml<OffsetData[]>(offsetsFile);
			for (int index = 0; index < offsets.Length; ++index)
			{
				Console.WriteLine(((ShipClass)index).ToString());
				Console.WriteLine(offsets[index].BulletOffset);

				var engineOffsets = offsets[index].EngineOffsets;
				foreach (Vector4 vector in engineOffsets)
				{
					Console.WriteLine("  {0}", vector);
				}
				Console.WriteLine(String.Empty);
			}
		}

		[Test]
		public void SpaceshipDataTest()
		{
			String spaceshipFile = GetPath("Spaceship.txt");

			IList<String> spaceshipData = fileManager.LoadTxt(spaceshipFile);
			Assert.IsTrue(spaceshipData.Count > 0);

			String spaceship = spaceshipData[0];
			Console.WriteLine("Spaceship asset: {0}", spaceship);
		}

		[Test]
		public void WeaponDataTest()
		{
			String weaponFile = GetPath("Weapon.txt");

			IList<String> weaponData = fileManager.LoadTxt(weaponFile);
			Assert.IsTrue(weaponData.Count > 0);

			String weapon = weaponData[0];
			Console.WriteLine("Weapon asset: {0}", weapon);
		}

		private static String GetPath(String name)
		{
			return GetPath(Constants.DATA_DIRECTORY, name);
		}
		private static String GetPath(String fldr, String name)
		{
			String root = @"..\..\..\..\WindowsGame\WindowsGame\bin\x86\Debug\";
			String path = String.Format("{0}/{1}/{2}", Constants.ROOT_DIRECTORY, fldr, name);

			return String.Format("{0}{1}", root, path);
		}

		[TestFixtureTearDown]
		public void TestFixtureTearDown()
		{
			IoCContainer.Release();
		}
	}
}